
import java.awt.HeadlessException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;

public class ServerGUI extends javax.swing.JFrame {
    
    Connection dbConn = null;
    ResultSet rs = null;
    PreparedStatement prep = null;
    
    public ServerGUI() {
        initComponents();
        
        popActivateTable();
        popStudTable();
        popFacTable();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        startBtn = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        portTf = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        loginLogoutTa = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        logTa = new javax.swing.JTextArea();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        activateTable = new javax.swing.JTable();
        activateBtn = new javax.swing.JButton();
        refreshBtn = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        deleteStudBtn = new javax.swing.JButton();
        updateStudBtn = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        studTable = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        facTable = new javax.swing.JTable();
        updateFacBtn = new javax.swing.JButton();
        deleteFacBtn = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        startBtn.setText("Start");
        startBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startBtnActionPerformed(evt);
            }
        });

        jLabel1.setText("Port Number:");

        loginLogoutTa.setColumns(20);
        loginLogoutTa.setRows(5);
        jScrollPane1.setViewportView(loginLogoutTa);

        logTa.setColumns(20);
        logTa.setRows(5);
        jScrollPane2.setViewportView(logTa);

        activateTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "ID Number", "Last Name", "First Name", "Occupation", "Course", "Year Level", "Class Code", "Username", "Password"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true, true, false, true, true, true, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(activateTable);
        activateTable.getColumnModel().getColumn(0).setResizable(false);
        activateTable.getColumnModel().getColumn(3).setResizable(false);

        activateBtn.setText("Activate");
        activateBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                activateBtnActionPerformed(evt);
            }
        });

        refreshBtn.setText("Refresh");
        refreshBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                refreshBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(refreshBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(activateBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(activateBtn)
                    .addComponent(refreshBtn))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Activate Accounts", jPanel1);

        deleteStudBtn.setText("Delete");
        deleteStudBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteStudBtnActionPerformed(evt);
            }
        });

        updateStudBtn.setText("Update");
        updateStudBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateStudBtnActionPerformed(evt);
            }
        });

        studTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "ID Number", "Last Name", "First Name", "Occupation", "Course", "Year Level", "Class Code", "Username", "Password"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true, true, false, true, true, true, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane6.setViewportView(studTable);
        studTable.getColumnModel().getColumn(0).setResizable(false);
        studTable.getColumnModel().getColumn(3).setResizable(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(0, 422, Short.MAX_VALUE)
                        .addComponent(updateStudBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(deleteStudBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(deleteStudBtn)
                    .addComponent(updateStudBtn))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Student Accounts", jPanel2);

        facTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "ID Number", "Last Name", "First Name", "Occupation", "Username", "Password"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true, true, false, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane5.setViewportView(facTable);
        facTable.getColumnModel().getColumn(0).setResizable(false);
        facTable.getColumnModel().getColumn(3).setResizable(false);

        updateFacBtn.setText("Update");
        updateFacBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateFacBtnActionPerformed(evt);
            }
        });

        deleteFacBtn.setText("Delete");
        deleteFacBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteFacBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(updateFacBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(deleteFacBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(deleteFacBtn)
                    .addComponent(updateFacBtn))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Faculty Accounts", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(168, 168, 168)
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(portTf, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(startBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1)
                    .addComponent(jScrollPane2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(portTf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(startBtn))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void startBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startBtnActionPerformed
        try {
            Registry reg = LocateRegistry.createRegistry(Integer.parseInt(portTf.getText()));
            ServerServices stub = new ImpServerServices();
            reg.rebind("svc", stub);
            appendLog("Server is running at port " + Integer.parseInt(portTf.getText()) + ".");
            portTf.setText("");
        } catch (Exception e) {
            appendLog(e.getMessage());
        }
    }//GEN-LAST:event_startBtnActionPerformed

    private void activateBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_activateBtnActionPerformed
        int row = activateTable.getSelectedRow();
        String idNo = activateTable.getModel().getValueAt(row, 0).toString();
        String ln = activateTable.getModel().getValueAt(row, 1).toString();
        String fn = activateTable.getModel().getValueAt(row, 2).toString();
        String occ = activateTable.getModel().getValueAt(row, 3).toString();
        String c = activateTable.getModel().getValueAt(row, 4).toString();
        String yr = activateTable.getModel().getValueAt(row, 5).toString();
        String code = activateTable.getModel().getValueAt(row, 6).toString();
        String user = activateTable.getModel().getValueAt(row, 7).toString();
        String pass = activateTable.getModel().getValueAt(row, 8).toString();
        
        try{
             String query;
            dbConn = DbConnection.dbConn();
            if(occ.equals("Student")){
                query = "INSERT INTO Student (id_number, last_name, first_name, occupation, course, year_level, class_code, user_name, pass_word) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
                prep = dbConn.prepareStatement(query);
                prep.setString(1, idNo);
                prep.setString(2, ln);
                prep.setString(3, fn);
                prep.setString(4, occ);
                prep.setString(5, c);
                prep.setString(6, yr);
                prep.setString(7, code);
                prep.setString(8, user);
                prep.setString(9, pass);
                prep.execute();
                
                JOptionPane.showMessageDialog(this, "Account Activated");
                
                // deleting the record in the temporary file after account activation
                String sql = "DELETE FROM Temporary WHERE id_number = ?";
                prep = dbConn.prepareStatement(sql);
                prep.setString(1, idNo);
                prep.execute();
                
            }else{
                query = "INSERT INTO Faculty (id_number, last_name, first_name, occupation, user_name, pass_word) VALUES (?, ?, ?, ?, ?, ?)";
                //dbConn = DbConnection.dbConn();
                prep = dbConn.prepareStatement(query);
                prep.setString(1, idNo);
                prep.setString(2, ln);
                prep.setString(3, fn);
                prep.setString(4, occ);
                prep.setString(5, user);
                prep.setString(6, pass);
                prep.execute();
                
                JOptionPane.showMessageDialog(this, "Account Activated");
                
                // deleting the record in the temporary file after account activation
                String sql = "DELETE FROM Temporary WHERE id_number = ?";
                prep = dbConn.prepareStatement(sql);
                prep.setString(1, idNo);
                prep.execute();
            }
            dbConn.close();
            
            popActivateTable();
            popStudTable();
            popFacTable();
        }catch(SQLException | NumberFormatException | HeadlessException e){
            try {
                JOptionPane.showMessageDialog(this, "Account already exist.\nDeleting...");
                String sql = "DELETE FROM Temporary WHERE id_number = ?";
                prep = dbConn.prepareStatement(sql);
                prep.setString(1, idNo);
                prep.execute();
                
                popActivateTable();
                popStudTable();
                popFacTable();
                
            } catch (HeadlessException | SQLException ex) {
            }
        }
    }//GEN-LAST:event_activateBtnActionPerformed

    private void deleteStudBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteStudBtnActionPerformed
        int row = studTable.getSelectedRow();
        
        String idNo = studTable.getModel().getValueAt(row, 0).toString();
        
        try{
            String sql = "DELETE FROM Student WHERE id_number = ?";
            dbConn = DbConnection.dbConn();
            prep = dbConn.prepareStatement(sql);
            prep.setString(1, idNo);
            prep.execute();
            dbConn.close();
            
            popActivateTable();
            popStudTable();
            popFacTable();
            
            JOptionPane.showMessageDialog(this, "Account deleted.");
        }catch(Exception e){
            e.printStackTrace();
        }
    }//GEN-LAST:event_deleteStudBtnActionPerformed

    private void updateStudBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateStudBtnActionPerformed
        int row = studTable.getSelectedRow();
        
        String idNo = studTable.getModel().getValueAt(row, 0).toString();
        String ln = studTable.getModel().getValueAt(row, 1).toString();
        String fn = studTable.getModel().getValueAt(row, 2).toString();
        String occ = studTable.getModel().getValueAt(row, 3).toString();
        String c = studTable.getModel().getValueAt(row, 4).toString();
        String yr = studTable.getModel().getValueAt(row, 5).toString();
        String code = studTable.getModel().getValueAt(row, 6).toString();
        String user = studTable.getModel().getValueAt(row, 7).toString();
        String pass =studTable.getModel().getValueAt(row, 8).toString();
        
        try{
            String query = "UPDATE Student SET id_number = ?, last_name = ?, first_name = ?, occupation = ?, course = ?, year_level = ?, class_code = ?, user_name = ?, pass_word = ? WHERE id_number = ?";
            dbConn = DbConnection.dbConn();
            prep = dbConn.prepareStatement(query);
            prep.setString(1, idNo);
            prep.setString(2, ln);
            prep.setString(3, fn);
            prep.setString(4, occ);
            prep.setString(5, c);
            prep.setString(6, yr);
            prep.setString(7, code);
            prep.setString(8, user);
            prep.setString(9, pass);
            prep.setString(10, idNo);
            prep.executeUpdate();
            dbConn.close();
            
            popActivateTable();
            popStudTable();
            popFacTable();
            
            JOptionPane.showMessageDialog(this, "Account updated.");
        }catch(Exception e){
            e.printStackTrace();
        }
    }//GEN-LAST:event_updateStudBtnActionPerformed

    private void updateFacBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateFacBtnActionPerformed
        int row = facTable.getSelectedRow();
        
        String idNo = facTable.getModel().getValueAt(row, 0).toString();
        String ln = facTable.getModel().getValueAt(row, 1).toString();
        String fn = facTable.getModel().getValueAt(row, 2).toString();
        String occ = facTable.getModel().getValueAt(row, 3).toString();
        String user = facTable.getModel().getValueAt(row, 7).toString();
        String pass = facTable.getModel().getValueAt(row, 8).toString();
        
        try{
            String query = "UPDATE Faculty SET id_number = ?, last_name = ?, first_name = ?, occupation = ?, user_name = ?, pass_word = ? WHERE id_number = ?";
            dbConn = DbConnection.dbConn();
            prep = dbConn.prepareStatement(query);
            prep.setString(1, idNo);
            prep.setString(2, ln);
            prep.setString(3, fn);
            prep.setString(4, occ);
            prep.setString(5, user);
            prep.setString(6, pass);
            prep.setString(7, idNo);
            prep.executeUpdate();
            dbConn.close();
            
            popActivateTable();
            popStudTable();
            popFacTable();
            
            JOptionPane.showMessageDialog(this, "Account updated.");
        }catch(Exception e){
            e.printStackTrace();
        }
    }//GEN-LAST:event_updateFacBtnActionPerformed

    private void deleteFacBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteFacBtnActionPerformed
        int row = facTable.getSelectedRow();
        
        String idNo = facTable.getModel().getValueAt(row, 0).toString();
        
        try{
            String sql = "DELETE FROM Faculty WHERE id_number = ?";
            dbConn = DbConnection.dbConn();
            prep = dbConn.prepareStatement(sql);
            prep.setString(1, idNo);
            prep.execute();
            dbConn.close();
            
            popActivateTable();
            popStudTable();
            popFacTable();
            
            JOptionPane.showMessageDialog(this, "Account deleted.");
        }catch(Exception e){
            e.printStackTrace();
        }
    }//GEN-LAST:event_deleteFacBtnActionPerformed

    private void refreshBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshBtnActionPerformed
        popActivateTable();
    }//GEN-LAST:event_refreshBtnActionPerformed
    
    public void appendLog(String s){
        logTa.append(s + "\n");
    }
    
    public void popActivateTable(){
        try {
            String qry = "SELECT * FROM Temporary";
            dbConn = DbConnection.dbConn();
            prep = dbConn.prepareStatement(qry);
            rs = prep.executeQuery();
            activateTable.setModel(DbUtils.resultSetToTableModel(rs));
            dbConn.close();
        } catch (Exception e) {
        }
    }
    
    public void popStudTable(){
        try {
            String qry = "SELECT * FROM Student";
            dbConn = DbConnection.dbConn();
            prep = dbConn.prepareStatement(qry);
            rs = prep.executeQuery();
            studTable.setModel(DbUtils.resultSetToTableModel(rs));
            dbConn.close();
        } catch (Exception e) {
        }
    }
    
    public void popFacTable(){
        try {
            String qry = "SELECT * FROM Faculty";
            dbConn = DbConnection.dbConn();
            prep = dbConn.prepareStatement(qry);
            rs = prep.executeQuery();
            facTable.setModel(DbUtils.resultSetToTableModel(rs));
            dbConn.close();
        } catch (Exception e) {
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ServerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ServerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ServerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ServerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ServerGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton activateBtn;
    private javax.swing.JTable activateTable;
    private javax.swing.JButton deleteFacBtn;
    private javax.swing.JButton deleteStudBtn;
    private javax.swing.JTable facTable;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea logTa;
    private javax.swing.JTextArea loginLogoutTa;
    private javax.swing.JTextField portTf;
    private javax.swing.JButton refreshBtn;
    private javax.swing.JButton startBtn;
    private javax.swing.JTable studTable;
    private javax.swing.JButton updateFacBtn;
    private javax.swing.JButton updateStudBtn;
    // End of variables declaration//GEN-END:variables
}
